package string;

import java.lang.reflect.Array;

/**
 * 字符串转整数
 */
public class StringToInt {


  public int stringToInt(String str) {
    if (str == null) {
      return -1;
    }

    int result = 0;
    int count = 1;
    char[] charArray = str.toCharArray();
    for (int i = charArray.length - 1; i >= 0; i--) {
      if (charArray[i] == '-') {
        result = -result;
        return result;
      }
      result += (charArray[i] - '0') * count;
      count = count * 10;
    }

    return result;
  }


  public static void main(String args[]) {
    StringToInt stringToInt = new StringToInt();
    int result = stringToInt.stringToInt("12345");
    System.out.println(result);
  }
}
